package common.algorithm_and_data_structure;

/**
 * @author zhang hao dong
 * @date 2025-03-27 11:09
 * 数组栈
 */
public class ArrayStack {
    private String[] items;
    private int count;
    private int maxStack;

    public ArrayStack(int maxStack) {
        this.maxStack = maxStack;
        this.items = new String[maxStack];
        this.count = 0;
    }

    public boolean push(String item) {
        if (count == maxStack) { return false;}
        items[count++] = item;
        return true;
    }

    public String pop() {
        if (count == 0) {return null;}
        String item = items[--count];
        return item;
    }

    public static void main(String[] args) {
        ArrayStack stack = new ArrayStack(5);
        stack.push("Hello");
        stack.push("World");
        stack.push("Java");
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
    }
}
